Skip to content

ENH: Add initial BCI2000 .dat reader (preload-only)#13699

Open
HansujaB wants to merge 10 commits intomne-tools:mainfrom
HansujaB:add-bci2000-reader
Open

ENH: Add initial BCI2000 .dat reader (preload-only)#13699
HansujaB wants to merge 10 commits intomne-tools:mainfrom
HansujaB:add-bci2000-reader

Conversation

@HansujaB
Copy link

Reference issue (if any)

Fixes #13151

What does this implement/fix?

This PR adds basic support for reading BCI2000 .dat files via:

mne.io.read_raw_bci2k()

The implementation:

  • Parses minimal required header fields
  • Decodes signal and state vector
  • Maps StimulusCode to STI 014 stim channel
  • Returns a Raw object using RawArray
  • Includes deterministic unit tests with a synthetic demo file

Tests

  • Synthetic .dat generator included in tests

  • Verifies:

    • sampling rate
    • number of samples
    • stim channel creation
    • correct StimulusCode decoding
    • preload=False raises

Scope (Intentional Limitations)

  • preload=False is not supported (raises NotImplementedError)
  • Minimal header parsing (SamplingRate + State Vector Definition only)
  • Generic channel names (EEG1, EEG2, …)
  • No gain/scaling applied
  • Not added to _get_supported() (since .dat is already mapped to Curry)

The goal is to provide a correct, minimal reader that can be safely extended in follow-up PRs.

@HansujaB HansujaB requested a review from larsoner as a code owner February 27, 2026 16:36
Copy link
Member

@larsoner larsoner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't look too deeply at the code, but looks like a reasonable start! With something like this we'd want to see it used somewhere, too -- is there a good file we could download using pooch in an example and use in an examples/io/something.py or similar? We could do something like what's done here

https://github.com/mne-tools/mne-bids/blob/15ee0e48179181c66705931683e16272dfd97a9a/examples/convert_fieldtrip_emg.py#L61

Also did you use AI tools in developing this code? If so please disclose the nature of AI tool usage

from mne.io.bci2k import RawBCI2k, read_raw_bci2k


def _write_demo_bci2k(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A more modern way to do this would be to

Suggested change
def _write_demo_bci2k(
@pytest.fixture
def bci2k_path(tmp_path):
fname = tmp_path / "something"
...
return fname

and then you use this inside your test

Copy link
Author

@HansujaB HansujaB Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@larsoner Thanks a lot for your review!
I searched for an example file but couldn't really find one, although I came across PhysioNet bigP3BCI dataset. The problem is , they converted .dat files to EDF + file header, so we can't use it !

What we can do is (use the same approach to generate a small example file) :
We can generate a small BCI2000 .dat file using a short P3Speller session with minimal channels and then host a trimmed version (a few seconds only) .
If this approach is acceptable I can work on it , Let me know!

Regarding AI usage , I looked upon the major stuff and algorithm development myself but for debugging and redundancy reduction, I took the help of AI tools to increase my efficiency!

@HansujaB HansujaB requested a review from larsoner March 2, 2026 22:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BCI2000 .dat file reader

2 participants